package rabbitmq.Direct;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import org.apache.commons.io.FileUtils;
import rabbitmq.utils.MqUtil;

import java.io.File;

public class Consumer02 {

    private final static String queueName="direct_logs";

    public static void main(String[] args) throws Exception {
        MqUtil mqUtil=new MqUtil();
        Channel chananel = mqUtil.getChananel();
        chananel.exchangeDeclare(queueName, BuiltinExchangeType.DIRECT);

        String queue = chananel.queueDeclare().getQueue();
        System.out.println(queue);
        chananel.queueBind(queue,queueName,"info");
        chananel.queueBind(queue,queueName,"warning");
        System.out.println("数据正在写入。。。。。。。。。");
        DeliverCallback deliverCallback=(consumerTag,delivery)->{
            String message = new String(delivery.getBody());
            File file=new File("D:/test11.txt");
            FileUtils.writeStringToFile(file,message,"UTF-8");
            System.out.println("数据写入成功");

        };
        chananel.basicConsume(queue,true,deliverCallback,consurmerTag->{});
    }
}
